/* Original Author:  Dominick O'Dierno
 * Date: 2007
 * Description: The main starting point for DOMercury
 * 
 * --CHANGELOG--
 * 
 * */

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using ManagedWinapi;
using System.Text;
using ManagedWinapi.Windows;
using System.IO;


namespace DOMercury
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            {
#if RELEASE//Force only one instance of DOMercury to be open at once
                Process ThisProcess = Process.GetCurrentProcess();
                Process[] AllProcesses = Process.GetProcessesByName(ThisProcess.ProcessName);
                if (AllProcesses.Length > 1)
                {
                    //Close Elegantly
                }
                else
                {
#endif
                    try
                    {
                        Application.EnableVisualStyles();
                        Application.Run(new DOMercuryProgramFlowManager());
                    }
                    catch (Exception ex)
                    {
                        //If an exception bubbles up this far, add it to the error log
                        FileStream fs = new FileStream("errorlog.log", FileMode.Append, FileAccess.Write);
                        StreamWriter sw = new StreamWriter(fs);
                        sw.Write(DateTime.Now.ToString() + ": " + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + Environment.NewLine);
                        sw.Flush();
                        sw.Close();
                        fs.Close();
                    }
#if RELEASE
                }

#endif
            } 
        }
    }
}